<?php

namespace App\Admin\Controllers;

use App\Admin\Actions\Grid\WtPaid;
use App\Admin\Repositories\ReceivePaymentHeader;
use Dcat\Admin\Controllers\AdminController;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;

class ReceivePaymentHeaderController extends AdminController
{

    protected $title = "头数据";
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new ReceivePaymentHeader(), function (Grid $grid) {
            $grid->model()->orderByDesc("id");
            $grid->id->sortable();
            $grid->DocCode;

            $grid->pay_at('确认收款')->display(function ($value) {
                return $value ? "已收款" : "<span style='color: dodgerblue'>未收款</span>";
            });
//            $grid->printnum;
//            $grid->refcode;
            $grid->DocDate;
            $grid->Doctype;
            $grid->periodid;
            $grid->FormID;
            $grid->cashcode;
            $grid->cashName;
//            $grid->bankcode;
            $grid->HDText;
//            $grid->summoney;
//            $grid->natsummoney;
            $grid->DocStatus;
            $grid->EnterName;
            $grid->EnterDate;
//            $grid->ModifyName;
//            $grid->ModifyDate;
//            $grid->PostName;
//            $grid->PostDate;
            $grid->ObjType;
//            $grid->companyid;
//            $grid->companyname;
//            $grid->companyid2;
//            $grid->companyname2;
//            $grid->cashcode2;
//            $grid->cashname2;
//            $grid->bankcode2;
//            $grid->CancelFlag;
//            $grid->blclosed;
//            $grid->ClearDocCode;
            $grid->paymethod;
//            $grid->deptcode;
//            $grid->deptname;
            $grid->orgid;
            $grid->orgname;
            $grid->oppocompanyid;
            $grid->oppocompanyname;
//            $grid->refformid;
//            $grid->CheckCode;
//            $grid->docword;
//            $grid->sdgroup;
//            $grid->sdgroupname;
//            $grid->linkformid;
//            $grid->cltbrand;
//            $grid->ObjItem;
//            $grid->linkcode;
//            $grid->olddoccode;
//            $grid->cashtypeid;
//            $grid->cashtypename;
//            $grid->regage;
//            $grid->lastprintformid;
//            $grid->lastprintdocstatus;
//            $grid->lastprintnum;
//            $grid->hdcurrency;
//            $grid->hdexchange_rate;
            $grid->hdamount;
//            $grid->hdnatamount;
//            $grid->AccountLinkCode;
//            $grid->ReimburseCode;
//            $grid->ContractLinkCode;
//            $grid->ReimburseName;
//            $grid->CautionerCode;
//            $grid->CautionerName;
//            $grid->Cashier;
//            $grid->Checker;
//            $grid->HDmemo;
//            $grid->Checkflag;
//            $grid->LinkDoccode;
//            $grid->LinkType;
//            $grid->CreateFlag;
//            $grid->FTmoney;
//            $grid->FTcode;
//            $grid->watercode;
//            $grid->remitter;

            $grid->selector(
                function (Grid\Tools\Selector $selector) {
                    // 是否支付 规格筛选器
                    $selector->selectOne(
                        'pay_at',
                        '是否收款',
                        [
                            '已收款',
                            '未收款',
                            '所有',
                        ],
                        function ($query, $value) {
                            if ($value[0] == 1) {
                                $query->whereNull('pay_at');
                            } else {
                                if ($value[0] == 0) {
                                    $query->whereNotNull('pay_at');
                                }
                            }
                        }
                    );

                    $selector->selectOne(
                        'value',
                        '资金',
                        ["0-2999", "3000-5999", "6000-9999", "9999-99999"],
                        function ($query, $value) {
                            $between = [
                                [0, 2999],
                                [3000, 5999],
                                [6000, 9999],
                                [9999, 99999],
                            ];

                            $query->whereBetween('hdamount', $between[$value]);
                        }
                    );

                }
            );

            // 确认支付按钮
            $grid->actions(new WtPaid());
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
        
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new ReceivePaymentHeader(), function (Show $show) {
            $show->id;
            $show->DocCode;
            $show->printnum;
            $show->refcode;
            $show->DocDate;
            $show->Doctype;
            $show->periodid;
            $show->FormID;
            $show->cashcode;
            $show->cashName;
            $show->bankcode;
            $show->HDText;
            $show->summoney;
            $show->natsummoney;
            $show->DocStatus;
            $show->EnterName;
            $show->EnterDate;
            $show->ModifyName;
            $show->ModifyDate;
            $show->PostName;
            $show->PostDate;
            $show->ObjType;
            $show->companyid;
            $show->companyname;
            $show->companyid2;
            $show->companyname2;
            $show->cashcode2;
            $show->cashname2;
            $show->bankcode2;
            $show->CancelFlag;
            $show->blclosed;
            $show->ClearDocCode;
            $show->paymethod;
            $show->deptcode;
            $show->deptname;
            $show->orgid;
            $show->orgname;
            $show->oppocompanyid;
            $show->oppocompanyname;
            $show->refformid;
            $show->CheckCode;
            $show->docword;
            $show->sdgroup;
            $show->sdgroupname;
            $show->linkformid;
            $show->cltbrand;
            $show->ObjItem;
            $show->linkcode;
            $show->olddoccode;
            $show->cashtypeid;
            $show->cashtypename;
            $show->regage;
            $show->lastprintformid;
            $show->lastprintdocstatus;
            $show->lastprintnum;
            $show->hdcurrency;
            $show->hdexchange_rate;
            $show->hdamount;
            $show->hdnatamount;
            $show->AccountLinkCode;
            $show->ReimburseCode;
            $show->ContractLinkCode;
            $show->ReimburseName;
            $show->CautionerCode;
            $show->CautionerName;
            $show->Cashier;
            $show->Checker;
            $show->HDmemo;
            $show->Checkflag;
            $show->LinkDoccode;
            $show->LinkType;
            $show->CreateFlag;
            $show->FTmoney;
            $show->FTcode;
            $show->watercode;
            $show->remitter;
            $show->created_at;
            $show->updated_at;
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new ReceivePaymentHeader(), function (Form $form) {
            $form->display('id');
            $form->text('DocCode');
            $form->text('printnum');
            $form->text('refcode');
            $form->text('DocDate');
            $form->text('Doctype');
            $form->text('periodid');
            $form->text('FormID');
            $form->text('cashcode');
            $form->text('cashName');
            $form->text('bankcode');
            $form->text('HDText');
            $form->text('summoney');
            $form->text('natsummoney');
            $form->text('DocStatus');
            $form->text('EnterName');
            $form->text('EnterDate');
            $form->text('ModifyName');
            $form->text('ModifyDate');
            $form->text('PostName');
            $form->text('PostDate');
            $form->text('ObjType');
            $form->text('companyid');
            $form->text('companyname');
            $form->text('companyid2');
            $form->text('companyname2');
            $form->text('cashcode2');
            $form->text('cashname2');
            $form->text('bankcode2');
            $form->text('CancelFlag');
            $form->text('blclosed');
            $form->text('ClearDocCode');
            $form->text('paymethod');
            $form->text('deptcode');
            $form->text('deptname');
            $form->text('orgid');
            $form->text('orgname');
            $form->text('oppocompanyid');
            $form->text('oppocompanyname');
            $form->text('refformid');
            $form->text('CheckCode');
            $form->text('docword');
            $form->text('sdgroup');
            $form->text('sdgroupname');
            $form->text('linkformid');
            $form->text('cltbrand');
            $form->text('ObjItem');
            $form->text('linkcode');
            $form->text('olddoccode');
            $form->text('cashtypeid');
            $form->text('cashtypename');
            $form->text('regage');
            $form->text('lastprintformid');
            $form->text('lastprintdocstatus');
            $form->text('lastprintnum');
            $form->text('hdcurrency');
            $form->text('hdexchange_rate');
            $form->text('hdamount');
            $form->text('hdnatamount');
            $form->text('AccountLinkCode');
            $form->text('ReimburseCode');
            $form->text('ContractLinkCode');
            $form->text('ReimburseName');
            $form->text('CautionerCode');
            $form->text('CautionerName');
            $form->text('Cashier');
            $form->text('Checker');
            $form->text('HDmemo');
            $form->text('Checkflag');
            $form->text('LinkDoccode');
            $form->text('LinkType');
            $form->text('CreateFlag');
            $form->text('FTmoney');
            $form->text('FTcode');
            $form->text('watercode');
            $form->text('remitter');
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
